package mercurius.fitness.client.rb.exercise;

import java.util.ArrayList;
import java.util.Date;
import mercurius.fitness.client.locale.Locale;
import net.pleso.framework.client.bl.rb.columns.impl.RBColumn;
import net.pleso.framework.client.dal.IDataColumn;
import net.pleso.framework.client.dal.IDataRow;
import net.pleso.framework.client.dal.db.IDBValue;
import net.pleso.framework.client.dal.db.types.DBDate;
import net.pleso.framework.client.dal.db.types.DBFloat;
import net.pleso.framework.client.dal.db.types.DBInteger;
import net.pleso.framework.client.dal.db.types.DBString;
import net.pleso.framework.client.dal.impl.DataColumn;

public class Exercise extends ExerciseInfo implements IDataRow {
	
	private boolean isgps = false;
	private Integer points = new Integer(0);
	private Integer calories = new Integer(0);
	
	public Exercise() {
		
	}
	
	public Exercise(Integer id, 
			Date date,
			String duration,
			Float distance,
			String distance_unit,
			Integer avghr,
			Integer maxhr,
			Float avgspeed,
			Float bestspeed,
			String avgpace,
			String bestpace,
			String speed_unit,
			String z1,String z2, String z3, String z4, String z5,
			String activity,
			String notes,
			String title,
			String location,
			Integer pub) {
		super( id, 
				date,
				duration,
				distance,
				distance_unit,
				avghr,
				maxhr,
				avgspeed,
				bestspeed,
				avgpace,
				bestpace,
				speed_unit,
				z1, z2,  z3,  z4,  z5,
				activity,
				notes,
				title,
				location,
				pub);
	}
	
	public boolean isGPS() {
		return isgps;
	}
	
	public void setIsGPS(boolean v) {
		isgps = v;
	}
	
	public void setPoints(int p) {
		points = new Integer(p);
	}
	
	public Integer getPoints() {
		return points;
	}
	
	public void setCalories(int p) {
		calories = new Integer(p);
	}
	
	public Integer getCalories() {
		return calories;
	}
	
	public class id_column extends Columns {
		public id_column() {
			super("id", "Exercise ID", false);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBInteger(row.getID());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBInteger)
				row.setID(((DBInteger) value).getInteger());
		}
	}
	
	public class points_column extends Columns {
		public points_column() {
			super("points", "Total Points", true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBInteger(row.getPoints());
		}
		
		public void setCell(Exercise row, IDBValue value) {
		}
	}
	
	public class calories_column extends Columns {
		public calories_column() {
			super("calories", "Total Calories", true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBInteger(row.getCalories());
		}
		
		public void setCell(Exercise row, IDBValue value) {
		}
	}
	
	
	public class date_column extends Columns {
		
		public date_column() {
			super("date", Locale.constants().exercise_date_column(), false);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBDate(row.getDate());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBDate)
				row.setDate(((DBDate) value).getDate());
		}
	}	
	
	public class duration_column extends Columns {
		
		public duration_column() {
			super("duration", Locale.constants().exercise_duration_column(), false);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBString(row.getDuration());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBString)
				row.setDuration(((DBString) value).getString());
		}
	}
	
	public class distance_column extends Columns {
		
		public distance_column() {
			super("distance", Locale.constants().exercise_distance_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBFloat(row.getDistance());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBFloat)
				row.setDistance(((DBFloat) value).getFloat());
		}
	}
	
	
	public class distanceunit_column extends Columns {
		
		public distanceunit_column() {
			super("distance_unit", Locale.constants().exercise_distanceunit_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBString(row.getDistanceUnit());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBString)
				row.setDistanceUnit(((DBString) value).getString());
		}
	}
	
	
	public class avghr_column extends Columns {
		
		public avghr_column() {
			super("avg_hr", Locale.constants().exercise_avghr_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBInteger(row.getAvgHR());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBInteger)
				row.setAvgHR(((DBInteger) value).getInteger());
		}
	}
	
	public class maxhr_column extends Columns {
		
		public maxhr_column() {
			super("max_hr", Locale.constants().exercise_maxhr_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBInteger(row.getMaxHR());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBInteger)
				row.setMaxHR(((DBInteger) value).getInteger());
		}
	}
	
	public class avgspeed_column extends Columns {
		
		public avgspeed_column() {
			super("avg_speed", Locale.constants().exercise_avgspeed_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBFloat(row.getAvgSpeed());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBFloat)
				row.setAvgSpeed(((DBFloat) value).getFloat());
		}
	}
	
	public class bestspeed_column extends Columns {
		
		public bestspeed_column() {
			super("best_speed", Locale.constants().exercise_bestspeed_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBFloat(row.getBestSpeed());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBFloat)
				row.setBestSpeed(((DBFloat) value).getFloat());
		}
	}
	
public class avgpace_column extends Columns {
		
		public avgpace_column() {
			super("avg_pace", Locale.constants().exercise_avgpace_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBString(row.getAvgPace());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBFloat)
				row.setAvgPace(((DBString) value).getString());
		}
	}
	
	public class bestpace_column extends Columns {
		
		public bestpace_column() {
			super("best_pace", Locale.constants().exercise_bestpace_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBString(row.getBestPace());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBFloat)
				row.setBestPace(((DBString) value).getString());
		}
	}
	
	
	public class speedunit_column extends Columns {
		public speedunit_column() {
			super("speed_unit", Locale.constants().activity_speedunit_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBString(row.getSpeedUnit());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBString)
				row.setSpeedUnit(((DBString) value).getString());
		}
	}
	
	public class z1_column extends Columns {
		
		public z1_column() {
			super("z1_time", Locale.constants().exercise_z1_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBString(row.getZ1Time());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBString)
				row.setZ1Time(((DBString) value).getString());
		}
	}
	
	public class z2_column extends Columns {
		
		public z2_column() {
			super("z2_time", Locale.constants().exercise_z2_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBString(row.getZ2Time());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBString)
				row.setZ2Time(((DBString) value).getString());
		}
	}
	
	public class z3_column extends Columns {
		
		public z3_column() {
			super("z3_time", Locale.constants().exercise_z3_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBString(row.getZ3Time());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBString)
				row.setZ3Time(((DBString) value).getString());
		}
	}
	
	public class z4_column extends Columns {
		
		public z4_column() {
			super("z4_time", Locale.constants().exercise_z4_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBString(row.getZ4Time());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBString)
				row.setZ4Time(((DBString) value).getString());
		}
	}
	
	public class z5_column extends Columns {
		
		public z5_column() {
			super("z5_time", Locale.constants().exercise_z5_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBString(row.getZ5Time());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBString)
				row.setZ5Time(((DBString) value).getString());
		}
	}
	
	public class activity_column extends Columns {
		public activity_column() {
			super("activity", Locale.constants().activity_activity_column(), false);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBString(row.getActivity());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBString)
				row.setActivity(((DBString) value).getString());
		}
	}
	
	public class notes_column extends Columns {
		public notes_column() {
			super("notes", Locale.constants().exercise_notes_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBString(row.getNotes());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBString)
				row.setNotes(((DBString) value).getString());
		}
	}
	
	public class title_column extends Columns {
		public title_column() {
			super("title", Locale.constants().exercise_title_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBString(row.getTitle());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBString)
				row.setTitle(((DBString) value).getString());
		}
	}
	
	public class location_column extends Columns {
		public location_column() {
			super("location", Locale.constants().exercise_location_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBString(row.getLocation());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBString)
				row.setLocation(((DBString) value).getString());
		}
	}
	
	public class public_column extends Columns {
		public public_column() {
			super("public", Locale.constants().exercise_public_column(), true);
		}
		
		public IDBValue getCell(Exercise row) {
			return new DBInteger(row.getPublic());
		}
		
		public void setCell(Exercise row, IDBValue value) {
			if (value instanceof DBInteger)
				row.setPublic(((DBInteger) value).getInteger());
		}
	}
	
	private static ArrayList columns = new ArrayList();
	private static final Exercise instance = new Exercise();
	
	public static RBColumn[] getColumns() {
		RBColumn[] rbColumns = new RBColumn[] {
			//	new RBColumn(Exercise.Columns.id, 30),
				new RBColumn(Exercise.Columns.date, 30),
				new RBColumn(Exercise.Columns.duration, 30),
				new RBColumn(Exercise.Columns.activity, 30)
		};
		return rbColumns;
	}
	
	public abstract static class Columns extends DataColumn {
		
		public Columns(String name, String caption, boolean allowNull) {
			super(name, caption, allowNull);
			columns.add(this);
			this.order = columns.size(); 
		}
		
		
		public abstract void setCell(Exercise row, IDBValue value);
		public abstract IDBValue getCell(Exercise row);
		public static final id_column id = instance.new id_column();
		public static final points_column points = instance.new points_column();
		public static final calories_column calories = instance.new calories_column();
		public static final date_column date = instance.new date_column();
		public static final duration_column duration = instance.new duration_column();
		public static final distance_column distance = instance.new distance_column();
		public static final distanceunit_column distance_unit = instance.new distanceunit_column();
		public static final avghr_column avghr = instance.new avghr_column();
		public static final maxhr_column maxhr = instance.new maxhr_column();
		public static final avgspeed_column avgspeed = instance.new avgspeed_column();
		public static final bestspeed_column bestspeed = instance.new bestspeed_column();
		public static final avgpace_column avgpace = instance.new avgpace_column();
		public static final bestpace_column bestpace = instance.new bestpace_column();
		public static final speedunit_column speedunit = instance.new speedunit_column();
		
		public static final z1_column z1 = instance.new z1_column();
		
		public static final z2_column z2 = instance.new z2_column();
		public static final z3_column z3 = instance.new z3_column();
		public static final z4_column z4 = instance.new z4_column();
		public static final z5_column z5 = instance.new z5_column();
		public static final activity_column activity = instance.new activity_column();
		public static final notes_column notes = instance.new notes_column ();
		
		public static final title_column title = instance.new title_column ();
		public static final location_column location = instance.new location_column ();
		public static final public_column pub = instance.new public_column ();
		
		
		
		
	}
	
	
	
	
	
	public IDBValue getCell(IDataColumn column) {
		Columns col = (Columns) column;
		return col.getCell(this);
	}
	
	public IDataColumn getColumn(int index) {
		return (IDataColumn) columns.get(index);
	}
	
	public int getColumnCount() {
		return columns.size();
	}
	
	public void setCell(IDataColumn column, IDBValue value) {
		Columns col = (Columns) column;
		col.setCell(this, value);
	}
	
}
